<template>
  <el-dialog v-drag :title="!dataForm.resultId ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
      label-width="80px">
      <el-form-item label="验收单id" prop="acceptId">
        <el-input size="mini" v-model="dataForm.acceptId" placeholder="验收单id" clearable></el-input>
      </el-form-item>
      <el-form-item label="验收单号" prop="acceptNo">
        <el-input size="mini" v-model="dataForm.acceptNo" placeholder="验收单号" clearable></el-input>
      </el-form-item>
      <el-form-item label="验收单明细Id" prop="itmeId">
        <el-input size="mini" v-model="dataForm.itmeId" placeholder="验收单明细Id" clearable></el-input>
      </el-form-item>
      <el-form-item label="药品Id" prop="goodsId">
        <el-input size="mini" v-model="dataForm.goodsId" placeholder="药品Id" clearable></el-input>
      </el-form-item>
      <el-form-item label="抽样数量" prop="samplingNum">
        <el-input size="mini" v-model="dataForm.samplingNum" placeholder="抽样数量" clearable></el-input>
      </el-form-item>
      <el-form-item label="抽样合格数量" prop="samplingOkNum">
        <el-input size="mini" v-model="dataForm.samplingOkNum" placeholder="抽样合格数量" clearable></el-input>
      </el-form-item>
      <el-form-item label="抽样外观 1合格，0不合格" prop="isSamplingView">
        <el-input size="mini" v-model="dataForm.isSamplingView" placeholder="抽样外观 1合格，0不合格" clearable></el-input>
      </el-form-item>
      <el-form-item label="抽样包装 1合格，0不合格" prop="isSamplingPackage">
        <el-input size="mini" v-model="dataForm.isSamplingPackage" placeholder="抽样包装 1合格，0不合格" clearable></el-input>
      </el-form-item>
      <el-form-item label="抽样标签 1合格，0不合格" prop="isSamplingLabel">
        <el-input size="mini" v-model="dataForm.isSamplingLabel" placeholder="抽样标签 1合格，0不合格" clearable></el-input>
      </el-form-item>
      <el-form-item label="抽样标签 1有，0无" prop="hasSamplingInstruction">
        <el-input size="mini" v-model="dataForm.hasSamplingInstruction" placeholder="抽样标签 1有，0无" clearable></el-input>
      </el-form-item>
      <el-form-item label="合格证 1有，0无" prop="hasQualityCertificate">
        <el-input size="mini" v-model="dataForm.hasQualityCertificate" placeholder="合格证 1有，0无" clearable></el-input>
      </el-form-item>
      <el-form-item label="验收合格数量" prop="aacceptedQualityNum">
        <el-input size="mini" v-model="dataForm.aacceptedQualityNum" placeholder="验收合格数量" clearable></el-input>
      </el-form-item>
      <el-form-item label="检验报告书 1有，0无" prop="hasAacceptedReport">
        <el-input size="mini" v-model="dataForm.hasAacceptedReport" placeholder="检验报告书 1有，0无" clearable></el-input>
      </el-form-item>
      <el-form-item label="质量状况 1合格，0不合格" prop="qualityCondition">
        <el-input size="mini" v-model="dataForm.qualityCondition" placeholder="质量状况 1合格，0不合格" clearable></el-input>
      </el-form-item>
      <el-form-item label="验收结论 1合格，0不合格" prop="isAacceptedResult">
        <el-input size="mini" v-model="dataForm.isAacceptedResult" placeholder="验收结论 1合格，0不合格" clearable></el-input>
      </el-form-item>
      <el-form-item label="验收人Id" prop="aacceptedUserId">
        <el-input size="mini" v-model="dataForm.aacceptedUserId" placeholder="验收人Id" clearable></el-input>
      </el-form-item>
      <el-form-item label="验收人" prop="aacceptedUsername">
        <el-input size="mini" v-model="dataForm.aacceptedUsername" placeholder="验收人" clearable></el-input>
      </el-form-item>
      <el-form-item label="签字图片" prop="signPic">
        <el-input size="mini" v-model="dataForm.signPic" placeholder="签字图片" clearable></el-input>
      </el-form-item>
      <el-form-item label="牌照图片" prop="photoPic">
        <el-input size="mini" v-model="dataForm.photoPic" placeholder="牌照图片" clearable></el-input>
      </el-form-item>
      <el-form-item label="本地上传图片" prop="uploadPic">
        <el-input size="mini" v-model="dataForm.uploadPic" placeholder="本地上传图片" clearable></el-input>
      </el-form-item>
      <el-form-item label="门店id" prop="storeId">
        <el-input size="mini" v-model="dataForm.storeId" placeholder="门店id" clearable></el-input>
      </el-form-item>
      <el-form-item label="门店名称" prop="storeName">
        <el-input size="mini" v-model="dataForm.storeName" placeholder="门店名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="门店编码" prop="storeCode">
        <el-input size="mini" v-model="dataForm.storeCode" placeholder="门店编码" clearable></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input size="mini" v-model="dataForm.createTime" placeholder="创建时间" clearable></el-input>
      </el-form-item>
      <el-form-item label="修改时间" prop="updateTime">
        <el-input size="mini" v-model="dataForm.updateTime" placeholder="修改时间" clearable></el-input>
      </el-form-item>
      <el-form-item label="创建人" prop="createUsername">
        <el-input size="mini" v-model="dataForm.createUsername" placeholder="创建人" clearable></el-input>
      </el-form-item>
      <el-form-item label="创建人id" prop="createUserId">
        <el-input size="mini" v-model="dataForm.createUserId" placeholder="创建人id" clearable></el-input>
      </el-form-item>
      <el-form-item label="修改人" prop="updateUsername">
        <el-input size="mini" v-model="dataForm.updateUsername" placeholder="修改人" clearable></el-input>
      </el-form-item>
      <el-form-item label="修改人id" prop="updateUserId">
        <el-input size="mini" v-model="dataForm.updateUserId" placeholder="修改人id" clearable></el-input>
      </el-form-item>
      <el-form-item label="是否可用 1:是" prop="status">
        <el-input size="mini" v-model="dataForm.status" placeholder="是否可用 1:是" clearable></el-input>
      </el-form-item>
      <el-form-item label="是否删除 1:是" prop="isDeleted">
        <el-input size="mini" v-model="dataForm.isDeleted" placeholder="是否删除 1:是" clearable></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input size="mini" v-model="dataForm.remark" placeholder="备注" clearable></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          resultId: 0,
          acceptId: '',
          acceptNo: '',
          itmeId: '',
          goodsId: '',
          samplingNum: '',
          samplingOkNum: '',
          isSamplingView: '',
          isSamplingPackage: '',
          isSamplingLabel: '',
          hasSamplingInstruction: '',
          hasQualityCertificate: '',
          aacceptedQualityNum: '',
          hasAacceptedReport: '',
          qualityCondition: '',
          isAacceptedResult: '',
          aacceptedUserId: '',
          aacceptedUsername: '',
          signPic: '',
          photoPic: '',
          uploadPic: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          acceptId: [{
            required: true,
            message: '验收单id不能为空',
            trigger: 'blur'
          }],
          acceptNo: [{
            required: true,
            message: '验收单号不能为空',
            trigger: 'blur'
          }],
          itmeId: [{
            required: true,
            message: '验收单明细Id不能为空',
            trigger: 'blur'
          }],
          goodsId: [{
            required: true,
            message: '药品Id不能为空',
            trigger: 'blur'
          }],
          samplingNum: [{
            required: true,
            message: '抽样数量不能为空',
            trigger: 'blur'
          }],
          samplingOkNum: [{
            required: true,
            message: '抽样合格数量不能为空',
            trigger: 'blur'
          }],
          isSamplingView: [{
            required: true,
            message: '抽样外观 1合格，0不合格不能为空',
            trigger: 'blur'
          }],
          isSamplingPackage: [{
            required: true,
            message: '抽样包装 1合格，0不合格不能为空',
            trigger: 'blur'
          }],
          isSamplingLabel: [{
            required: true,
            message: '抽样标签 1合格，0不合格不能为空',
            trigger: 'blur'
          }],
          hasSamplingInstruction: [{
            required: true,
            message: '抽样标签 1有，0无不能为空',
            trigger: 'blur'
          }],

          hasQualityCertificate: [{
            required: true,
            message: '合格证 1有，0无不能为空',
            trigger: 'blur'
          }],
          aacceptedQualityNum: [{
            required: true,
            message: '验收合格数量不能为空',
            trigger: 'blur'
          }],
          hasAacceptedReport: [{
            required: true,
            message: '检验报告书 1有，0无不能为空',
            trigger: 'blur'
          }],
          qualityCondition: [{
            required: true,
            message: '质量状况 1合格，0不合格不能为空',
            trigger: 'blur'
          }],
          isAacceptedResult: [{
            required: true,
            message: '验收结论 1合格，0不合格不能为空',
            trigger: 'blur'
          }],
          aacceptedUserId: [{
            required: true,
            message: '验收人Id不能为空',
            trigger: 'blur'
          }],
          aacceptedUsername: [{
            required: true,
            message: '验收人不能为空',
            trigger: 'blur'
          }],
          signPic: [{
            required: true,
            message: '签字图片不能为空',
            trigger: 'blur'
          }],
          photoPic: [{
            required: true,
            message: '牌照图片不能为空',
            trigger: 'blur'
          }],
          uploadPic: [{
            required: true,
            message: '本地上传图片不能为空',
            trigger: 'blur'
          }],
          storeId: [{
            required: true,
            message: '门店id不能为空',
            trigger: 'blur'
          }],
          storeName: [{
            required: true,
            message: '门店名称不能为空',
            trigger: 'blur'
          }],
          storeCode: [{
            required: true,
            message: '门店编码不能为空',
            trigger: 'blur'
          }],
          createTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }],
          updateTime: [{
            required: true,
            message: '修改时间不能为空',
            trigger: 'blur'
          }],
          createUsername: [{
            required: true,
            message: '创建人不能为空',
            trigger: 'blur'
          }],
          createUserId: [{
            required: true,
            message: '创建人id不能为空',
            trigger: 'blur'
          }],
          updateUsername: [{
            required: true,
            message: '修改人不能为空',
            trigger: 'blur'
          }],
          updateUserId: [{
            required: true,
            message: '修改人id不能为空',
            trigger: 'blur'
          }],
          status: [{
            required: true,
            message: '是否可用 1:是不能为空',
            trigger: 'blur'
          }],
          isDeleted: [{
            required: true,
            message: '是否删除 1:是不能为空',
            trigger: 'blur'
          }],
          remark: [{
            required: true,
            message: '备注不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.resultId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.resultId) {
            const res = await this.$http({
              url: `/purchase/purchaseacceptresult/info/${this.dataForm.resultId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
            let data = res.data
            if (data && data.code === 0) {
              this.dataForm = data.purchaseAcceptResult
            }
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url: `/purchase/purchaseacceptresult/${!this.dataForm.resultId ? 'save' : 'update'}`,
              method: 'post',
              data: this.$http.adornData(this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
